/**
 * 示例配置文件
 * 用于演示如何在Electron应用中使用JavaScript格式的配置文件
 */

import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
import icon from '../../../resources/icon.png'

const __filename = fileURLToPath(import.meta.url)
const __dirname_local = dirname(__filename)

// 基础配置
const baseConfig = {
  appName: 'RTSP-to-HLS-Streaming-Server',
  version: '1.0.0',
  author: 'Yunzhh.com',
  workspacePath: 'C:\\VideoDashboard\\RTSP2HLS' // 工作目录，
}

const browserWindowConfig = {
  width: 1920,
  height: 1080,
  show: false,
  title: 'RTSP to HLS Transcoder',
  autoHideMenuBar: false, // 修改为false，这样菜单就不会自动隐藏
  ...(process.platform === 'linux' ? { icon } : {}),
  webPreferences: {
    preload: join(__dirname_local, 'preload/preload.js'), // 修复路径，去掉../
    sandbox: false,
    // 添加一些调试选项
    devTools: true,
    // 修复本地资源加载问题
    webSecurity: false
  }
}

// 服务器配置
const httpServerConfig = {
  defaultPort: 8080,
  runningPort: null, // 运行时设置
  host: 'localhost',
  maxConnections: 100,
  timeout: 30000,
  sslEnabled: false,
  // 可以包含计算逻辑
  isProduction: process.env.NODE_ENV === 'production',
  getBaseUrl() {
    return `${this.sslEnabled ? 'https' : 'http'}://${this.host}:${this.port}`
  },
  setRunningPort(port) {
    this.runningPort = port
  }
}

// 媒体处理配置
const rtsp2hlsConfig = {
  ffmpeg: {
    path: '', // 将在运行时设置
    timeout: 60000,
    logLevel: 'info'
  },
  hls: {
    segmentTime: 10,
    playlistSize: 6,
    outputDir: 'hls_output',
    maxBitrate: '2000k',
    qualityLevels: [
      { name: 'high', resolution: '1280x720', bitrate: '2000k' },
      { name: 'medium', resolution: '854x480', bitrate: '1000k' },
      { name: 'low', resolution: '426x240', bitrate: '500k' }
    ]
  }
}

// 日志配置
const logConfig = {
  level: 'info',
  file: './logs/app.log',
  rotation: {
    maxSize: '10mb',
    maxFiles: 5
  },
  console: true
}

// 合并所有配置
const appConfig = {
  ...baseConfig,
  browserWindowConfig,
  httpServerConfig: httpServerConfig,
  rtsp2hlsConfig: rtsp2hlsConfig,
  logConfig: logConfig,
  // 环境特定配置覆盖
  ...(process.env.NODE_ENV === 'development' && {
    debugMode: true,
    log: {
      ...logConfig,
      level: 'debug'
    }
  })
}

// 导出配置模块
export default appConfig

export { baseConfig, browserWindowConfig, httpServerConfig, rtsp2hlsConfig, logConfig, appConfig }
